package com.customization.assets.util;

import com.customization.commons.Console;
import com.customization.commons.LogTool;
import weaver.general.Util;
import weaver.soa.workflow.request.*;
import weaver.workflow.workflow.WorkflowVersion;

import java.util.List;
import java.util.Map;

/**
 * @author	Huangwm
 * @description 资产数据动态提醒发送流程类
 */
public class AssetRemind {

    private LogTool log = new LogTool("/log/assetlog/huangwm/AssetRemind",false);
    private static DBTools dbTools = new DBTools();
    private static DateTools dateTools = new DateTools();

    /**
     * 设置提醒流程流转信息
     * @param userid 创建人
     * @param title 标题
     * @param mainMap 主表数据
     * @return RequestInfo
     * @throws Exception
     */
    public  RequestInfo setRequestInfo(String userid, String title, Map<String, String> mainMap) throws Exception{
        RequestInfo requestInfo = new RequestInfo();
        String activeWFID = WorkflowVersion.getActiveVersionWFID("165");
        log.writeLog("获取到的活动版本workflowid  "+activeWFID);
        requestInfo.setWorkflowid(activeWFID);
        requestInfo.setIsNextFlow("1");
        requestInfo.setCreatorid(userid);
        requestInfo.setDescription(title);
        requestInfo.setMainTableInfo(setMainTableInfo(mainMap));
        return requestInfo;
    }

    /**
     * 设置主表字段
     * @param fieldName
     * @param fieldValue
     * @return
     */
    public Property setMainField(String fieldName, String fieldValue){
        Property field = new Property();
        field.setName(fieldName);
        field.setValue(fieldValue);
        return field;
    }

    /**
     * 设置明细表字段
     * @param fieldName
     * @param fieldValue
     * @return
     */
    public Cell setDetailField(String fieldName, String fieldValue){
        Cell field = new Cell();
        field.setName(fieldName);
        field.setValue(fieldValue);
        return field;
    }

    /**
     * 设置归还流程主表数据
     * @param params
     * @return
     */
    public MainTableInfo setMainTableInfo(Map<String, String> params){
        log.writeLog("开始设置资产动态数据提醒流程信息");
        MainTableInfo mainTableInfo = new MainTableInfo();
        mainTableInfo.addProperty(setMainField("xglc", Util.null2String(params.get("xglc"))));//相关流程
        mainTableInfo.addProperty(setMainField("xgzc",Util.null2String(params.get("xgzc"))));//相关资产
        mainTableInfo.addProperty(setMainField("xgbm",Util.null2String( params.get("xgbm"))));//相关部门
        mainTableInfo.addProperty(setMainField("bz",Util.null2String( params.get("bz"))));//备注
        mainTableInfo.addProperty(setMainField("txr", Util.null2String(params.get("txr"))));//提醒人
        mainTableInfo.addProperty(setMainField("tzr", Util.null2String(params.get("tzr"))));//通知人
        log.writeLog("流程主表设置完成");
        return mainTableInfo;
    }

}
